﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRC.Clases;
using NHibernate;
using CRC.NHibernate;
using CRC.GestionSalones.Dominio.Clases;

namespace CRC.Inspecciones.Dominio.Controlador
{
    class Controlador_ModificarInspector
    {
        private Persona inspector = null;

        public Persona obtieneInspector(int pIntInspector) 
        {
            ISession session = null;
            ITransaction tx = null;
            Persona inspector = null;

            try 
            {
                session = NHibernateHelper.GetCurrentSession();
                tx = session.BeginTransaction();
                
                inspector = (Persona)session.Load(typeof(Persona), pIntInspector);
                
                tx.Commit();
                this.inspector = inspector;
                return inspector;

            }
            catch (HibernateException he)
            {
                if (tx != null) { tx.Rollback(); }
                session.Close();
                throw he;
            }
        }

        public Persona modificarInspector(
            string pstrNombre,
            string pstrAp1,
            string pstrAp2,
            string pstrFijo,
            string pstrMovil1,
            string pstrMovil2,
            string pstrEmail
            )
        {
            ISession session = null;
            ITransaction tx = null;

            try
            {
                session = NHibernateHelper.GetCurrentSession();
                tx = session.BeginTransaction();

                this.inspector.Nombre = pstrNombre;
                this.inspector.Apellido1 = pstrAp1;
                this.inspector.Apellido2 = pstrAp2;
                this.inspector.TelefonoFijo = pstrFijo;
                this.inspector.TelefonoMovil1 = pstrMovil1;
                this.inspector.TelefonoMovil2 = pstrMovil2;
                this.inspector.Email = pstrEmail;

                session.Update(this.inspector);
                tx.Commit();
                return inspector;

            }
            catch (HibernateException he)
            {
                if (tx != null) { tx.Rollback(); }
                session.Close();
                throw he;
            }

        }
    }
}
